﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TerraLAN_Downloader
{
    public partial class FormSettings : Form
    {
        public FormSettings()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            
            textBoxIP.Text = TerraLAN_Downloader.Properties.Settings.Default.ip;
            textBoxPort.Text = TerraLAN_Downloader.Properties.Settings.Default.port;
            textBoxGamesPath.Text = TerraLAN_Downloader.Properties.Settings.Default.GAMES_DIR;
            textBoxPseudo.Text = TerraLAN_Downloader.Properties.Settings.Default.pseudo;
            checkBox_bureau.Checked = TerraLAN_Downloader.Properties.Settings.Default.shortcut_desktop;
            checkBox_startmenu.Checked = TerraLAN_Downloader.Properties.Settings.Default.shortcut_start;
            checkBox_modeSocial.Checked = TerraLAN_Downloader.Properties.Settings.Default.mode_social;
            textBox_social.Text = TerraLAN_Downloader.Properties.Settings.Default.social_expiration.ToString();

            buttonSave.Enabled = false;
        }

        private void ParamsChanged(object sender, EventArgs e)
        {
            buttonSave.Enabled = true;

        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            buttonSave.Enabled = false;

            TerraLAN_Downloader.Properties.Settings.Default.ip = textBoxIP.Text;
            TerraLAN_Downloader.Properties.Settings.Default.port = textBoxPort.Text;
            TerraLAN_Downloader.Properties.Settings.Default.GAMES_DIR = textBoxGamesPath.Text;
            TerraLAN_Downloader.Properties.Settings.Default.pseudo = textBoxPseudo.Text;
            TerraLAN_Downloader.Properties.Settings.Default.shortcut_desktop = checkBox_bureau.Checked;
            TerraLAN_Downloader.Properties.Settings.Default.shortcut_start = checkBox_startmenu.Checked;
            TerraLAN_Downloader.Properties.Settings.Default.mode_social = checkBox_modeSocial.Checked;
            TerraLAN_Downloader.Properties.Settings.Default.social_expiration = Int32.Parse(textBox_social.Text);

            if (TerraLAN_Downloader.Properties.Settings.Default.pseudo == "")
                TerraLAN_Downloader.Properties.Settings.Default.pseudo = System.Environment.MachineName;

            TerraLAN_Downloader.Properties.Settings.Default.Save();
            this.Close();
        }

        private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = textBoxGamesPath.Text;
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                textBoxGamesPath.Text = folderBrowserDialog1.SelectedPath;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            System.Collections.Specialized.StringCollection tmp = TerraLAN_Downloader.Properties.Settings.Default.installList;
            System.Collections.Specialized.StringCollection tmp2 = TerraLAN_Downloader.Properties.Settings.Default.versionsList;
            TerraLAN_Downloader.Properties.Settings.Default.Reset();
            TerraLAN_Downloader.Properties.Settings.Default.installList = tmp;
            TerraLAN_Downloader.Properties.Settings.Default.versionsList = tmp2;
            TerraLAN_Downloader.Properties.Settings.Default.pseudo = System.Environment.MachineName;
            TerraLAN_Downloader.Properties.Settings.Default.Save();

            Form2_Load(null, null);
            buttonSave.Enabled = false;
        }
    }
}
